$(function(){
	var ary = new Array();
	var $modal = $('#my-modal-loading');
	var page = 1;
	var query_id = localStorage.getItem("query_id");
	console.log("store_id:" + query_id);
	var urlPath = "http://yx.fxtourong.com/V1/Circle/approvalList" + "?store_id=" + query_id;
	var urlPath2 = "http://yx.fxtourong.com/V1/Circle/isPassApproval" + "?store_id=" + query_id;
	var btn = $("#bottom_more");
	$modal.modal();
	getData();
	
	btn.click(function(){
		$modal.modal();
		page = page + 1;
		getData();
	});
		
	function getData(){
		$.ajax({
			type: "POST",
			url: urlPath,
			data: {
				token : localStorage.getItem("token"),
				page : page
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				var code = data.code;
				console.log(code);
				if(code == "1") {
					btn.css("display", "block");
					var jsonStr = data.data;
					for(var i = 0; i<jsonStr.length; i++){
							var industry = jsonStr[i];
							ary.push(industry);
							console.log(industry.identity);
							$("#member_ul").append("<li style='height:1px;'><div style='height:1px;border-bottom:1px solid #f5f6f7'></div></li><li value='" + (((page-1) * 10) + i) + "' class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left'>" + 
						        "<div class='am-u-sm-2 am-list-thumb'>" +
						         "<img class='am-circle' src='" + industry.avatar + "' style='width: 48px;height: 48px;margin-left: 10px;'/>" + 
						        "</div>" + 
						        "<div class=' am-u-sm-3 am-list-main' style='margin-top: 10px;'>" + 
						            "<p class='am-list-item-text'><span style='font-size: 16px;margin-left: 8px;'>" + industry.nickname + "</span></p>" + 
						        "</div>" +
						        "<div class=' am-u-sm-7 am-list-main' style='margin-top: 10px;'>" + 
						        	"<button value='" + (i + 10*(page - 1)) + "' class='am-btn am-btn-secondary spYes' style='font-size: 13px;float: right;margin-right: 15px;display:inline;border-radius: 3px;padding: 7px 10px;' onclick=''>" + "通过" + "</button>" +
						            "<button value='" + (i + 10*(page - 1)) + "' class='am-btn spNo' style='font-size: 13px;float: right;margin-right: 15px;display:inline;border-radius: 3px;padding: 7px 10px;color: #ffffff;background-color: #999;border-color: #999;'onclick=''>" + "拒绝" + "</button>" +
						        "</div>" +
					      	"</li>");
						}	
				} else {
					btn.css("display", "none");
					if(page == 1){
						$("#empty_img").css("display", "block");
					}
				}
			},
			error: function(e){
				$modal.modal('close');
			}
		});
	}
	
//	$(document).on("click touchstart","li",function(){
////		alert($(this).val()); //弹出点击的li标签的value值
////		if(controller == 1){
////			console.log($(this).val());
////		}
//		var m = $(this).val();
//		var headImage = localStorage.getItem("head_image"); //我的头像
//		console.log("image1:" + headImage);
//		var imagehead = ary[m].avatar;
//		console.log("image2:" + imagehead);
//		if(headImage == imagehead){
//			alert("不能给自己发私信")
//		} else {
//			$(this).addClass('shit');
//			localStorage.setItem("person_id", ary[m].identity);
//			console.log(ary[$(this).val()].identity);
//			location.href = "person_main.html";
//		}
//		
//	}); 
	
	$(document).on("click",".spYes",function(){
			var sp2 = $(this).val();
			var sp = $(this).text();
			localStorage.setItem("person_id", ary[sp2].identity);
			console.log(ary[sp2].identity);
			if(sp == "通过"){
				$.ajax({
					type: "POST",
					url: urlPath2,
					data: {
						token : localStorage.getItem("token"),
						approval_id: ary[sp2].id,
						type: 1
					},
					dataType: "json",
					success: function(data) {
						console.log(data);
						var code = data.code;
						console.log(code);
						if(code == "1") {
							new Toast({context:$('body'),message:'通过'});
						} 
					}
				});
			} 
		return false;	
	});
	
	$(document).on("click",".spNo",function(){
			var sp2 = $(this).val();
			var sp = $(this).text();
			localStorage.setItem("person_id", ary[sp2].identity);
			console.log(ary[sp2].identity);
			if(sp == "拒绝"){
				$.ajax({
					type: "POST",
					url: urlPath2,
					data: {
						token : localStorage.getItem("token"),
						approval_id: ary[sp2].id,
						type: 2
					},
					dataType: "json",
					success: function(data) {
						console.log(data);
						var code = data.code;
						console.log(code);
						if(code == "1") {
							new Toast({context:$('body'),message:'拒绝'});
						} 
					}
				});
			} 
		return false;	
	});
	
	
});
